package com.example.module_filemanage.Adapter;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.module_filemanage.MVVM.Module.Entil.Item_Left_Menu_Module;
import com.example.module_filemanage.Public.BodyColor;
import com.example.module_filemanage.R;
import com.example.module_filemanage.databinding.FmItemDrawermenuBinding;


import java.security.PublicKey;
import java.util.ArrayList;

import static android.content.ContentValues.TAG;

/**
 * Created by SJ on 2018/4/20.
 */

public class LeftMenu_Adapter extends RecyclerView.Adapter<LeftMenu_Adapter.LeftMenu_ViewHolder> {
    ArrayList<Item_Left_Menu_Module> items;
    FmItemDrawermenuBinding binding;
    private Context mContext;
    public LeftMenu_Adapter(Context mContext,ArrayList<Item_Left_Menu_Module> item){
        Log.e(TAG, "onBindViewHolder: ");
        this.items=item;
        this.mContext=mContext;
    }

    @Override
    public LeftMenu_ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        binding = DataBindingUtil.inflate(LayoutInflater
                .from(parent.getContext()), R.layout.fm_item_drawermenu, parent, false);
        LeftMenu_ViewHolder holder = new LeftMenu_ViewHolder(binding);
        Log.e(TAG, "onBindViewHolder: ");
        holder.setDataBinding(binding);
        return holder;
    }

    @Override
    public void onBindViewHolder(LeftMenu_ViewHolder holder, int position) {
        Log.e(TAG, "onBindViewHolder: "+String.valueOf(position) );
        holder.getDataBinding().setItems(items.get(position));
        holder.getDataBinding().fmPress.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View IView) {

            }
        });
        holder.getDataBinding().executePendingBindings();
    }

    @Override
    public int getItemCount() {
        return items.size();
    }

    public static class LeftMenu_ViewHolder extends RecyclerView.ViewHolder{


       FmItemDrawermenuBinding mDataBinding;
       public  LeftMenu_ViewHolder(ViewDataBinding mDataBinding) {
           super(mDataBinding.getRoot());
       }
       public  FmItemDrawermenuBinding getDataBinding() {
           return mDataBinding;
       }

       public void setDataBinding(FmItemDrawermenuBinding IDataBinding) {
           mDataBinding=IDataBinding;
       }

   }
   public void setBackground(){
       binding.fmPress.setBackgroundColor(Color.BLACK);
       notifyDataSetChanged();
   }

}
